﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>CorkBoard It!</title>
</head>

<body>

<?php
	session_start();
	
	$host="localhost";
	$username="root";
	$password="";
	$database="cs4400_group17";

	mysql_connect($host,$username,$password);
	@mysql_select_db($database) or die( "Unable to select database");
	
	$username = $_SESSION['userName'];
	$useremail = $_SESSION['userEmail'];
	
	$corkboardEmail = $_POST['corkboardEmail'];
	$corkboardTitle = $_POST['corkboardTitle'];
	$corkboardCategoryName = $_POST['corkboardCategoryName'];
	$corkboardLastUpdate = $_POST['corkboardLastUpdate'];
	
	$sql = "SELECT Name from user WHERE Email='$corkboardEmail'";
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
	$corkboardOwnerName = $row[0];
?>

<div id="masthead">
	<h1>CorkBoard<span style="color:red;">It</span></h1>
	<p style="color:orange;margin-top:-10px"><b>Explore. Share. Inspire.</b></p>
</div>

<div id="container">
	<div id="page_content">
		<h1>User: <?php echo $corkboardOwnerName. ' (' .$corkboardEmail . ')';?></h1>
		<h2>Title: <?php echo $corkboardTitle;?></h2>
		<h2>Category: <?php echo $corkboardCategoryName;?></h2>
		<p>Last Updated: <?php echo $corkboardLastUpdate;?></p>
	</div>
	
	<div id="pushpins">
		<h2>Pushpins</h2>
		<?php
			$sql = "SELECT * FROM pushpin WHERE Email = '$corkboardEmail' AND Title = '$corkboardTitle'";
			$result = mysql_query($sql);
			while ($rows = mysql_fetch_array($result)) {
		?>
		<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
			<tr>
				<td>
					<form action='ViewPushpin.php' method='post'>
						<input type="hidden" name="pushpinEmail" value="<?php echo $rows['Email'];?>">
						<input type="hidden" name="pushpinTitle" value="<?php echo $rows['Title'];?>">
						<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
							<tr>
								<td>Picture</td>
								<td>:</td>
								<td><img src="<?php echo $rows['URL']; ?>"/>
									<input type="hidden" name="pushpinURL" value="<?php echo $rows['URL'];?>"></td>
							</tr>
							<tr>
								<td>Date</td>
								<td>:</td>
								<td><?php echo $rows['DateTime']; ?>
									<input type="hidden" name="pushpinDateTime" value="<?php echo $rows['DateTime'];?>"></td>
							</tr>
							<tr>
								<td width="117">Description</td>
								<td width="14">:</td>
								<td width="357"><?php echo $rows['Description']; ?>
									<input type="hidden" name="pushpinDescription" value="<?php echo $rows['Description'];?>"></td>
							</tr>
							<tr>
								<td></td>
								<td></td>
								<td><input type="submit" value="Go to Pushpin"/></td>
							</tr>
						</table>
					</form>
				</td>
			</tr>
		</table>
		<BR>
		<?php
			}
			$count=mysql_num_rows($result);
			
			if($count < 1){
				echo "<p>This Corkboard has no Pushpins</p>";
			}
		?>
	</div>
</div>

<div id="footer">
	
	<p>This CorkBoard has 
		<?php
			$qry = "SELECT * FROM `userwatches` WHERE OwnerEmail = '$corkboardEmail' AND Title = '$corkboardTitle'";
			$result = mysql_query($qry);
			$row = mysql_fetch_array($result);
			$count=mysql_num_rows($result);
			echo $count;
		?>
		watchers.
	</p>
	
	<?php 
	if($corkboardEmail == $useremail){
		echo "<form action='AddPushpin.php' method='get'>";
		echo "<input type='hidden' name='corkTitle' value='$corkboardTitle'>";
		echo "<input type='submit' value='Add Pushpin'/>";
		echo "</form>";
	} else	{
		
		echo "<a href='watchCB.php?corkTitle=$corkboardTitle&OwnerEmail=$corkboardEmail'> Watch This Corkboard </a>";
		echo "<br />";
		echo "<a href='followUser.php?corkTitle=$corkboardTitle&OwnerEmail=$corkboardEmail'> Follow This User </a>";
		
	}
	?>
	
	<form name = "input" action = "home.php" method = "post">
		<input type="submit" value="Back to Home" name="backtohome"/>
	</form>
	
</div>

</body>

</html>
